/*
 * @lc app=leetcode.cn id=682 lang=cpp
 *
 * [682] 棒球比赛
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int calPoints(vector<string> &operations)
    {
        vector<int> v;
        for (auto &s : operations)
        {
            if (s[0] == '-' || (s[0] >= '0' && s[0] <= '9'))
            {
                v.push_back(std::stoi(s));
            }
            else
            {
                switch (s[0])
                {
                case '+':
                    v.push_back(v[v.size() - 1] + v[v.size() - 2]);
                    break;
                case 'D':
                    v.push_back(v[v.size() - 1] * 2);
                    break;
                case 'C':
                    v.erase(v.end() - 1);
                    break;

                default:
                    break;
                }
            }
        }
        return std::accumulate(v.begin(), v.end(), 0);
    }
};
// @lc code=end
